export default function ({ graph, clickLink, clickNode }) {
  function clickRisnNum(e) {
    e.item.getModel()?.linkable !== false &&
      clickLink &&
      clickLink(e, e.item.getModel())
  }

  function clickMoreLabel(e) {
    const { item } = e
    const data = graph.findDataById(item.getID())
    if (data?.hiddenChildren?.length > 0) {
      const parentNode = item.getNeighbors('source')[0]
      const parentData = graph.findDataById(parentNode.getID())
      parentData.children.splice(parentData.children.length - 1, 1)
      parentData.children = parentData.children.concat(data.hiddenChildren)
      graph.updateChildren(parentData.children, parentData.id)
    }
  }

  graph.on('risk-num-label:click', function (e) {
    clickRisnNum(e)
  })
  graph.on('risk-num-label:touchend', function (e) {
    clickRisnNum(e)
  })
  graph.on('risk-num-label:mouseenter', function (e) {
    if (e.item.getModel().linkable) {
      e.target.attr({
        opacity: 0.7,
      })
    }
  })
  graph.on('risk-num-label:mouseleave', function (e) {
    if (e.item.getModel().linkable) {
      e.target.attr({
        opacity: 1,
      })
    }
  })
  graph.on('more-label:mouseenter', function (e) {
    e.target.attr({
      opacity: 0.7,
    })
  })
  graph.on('more-label:mouseleave', function (e) {
    e.target.attr({
      opacity: 1,
    })
  })

  graph.on('more-label:click', function (e) {
    clickMoreLabel(e)
  })
  graph.on('more-label:touchend', function (e) {
    clickMoreLabel(e)
  })

  graph.on('node:click', function (e) {
    clickNode && clickNode(e, e.item.getModel())
  })
}
